<?php
//1.定义一个MySQL类
class MysqliHelper{
    //2.定义了4个空的变量（主机名，账号，密码，库名）
    public $host = "47.105.38.70"; //主机地址
    public $login = "root"; //登录账号
    public $password = "shtdx"; //密码
    public $dbname = "test"; //库名
    public $port = 3309; //端口
    public $link;//定义一个连接符
    //3.利用构造方法完成赋值操作
    function __construct(){
        //4.在赋值的基础上做了：连接数据库  设置字符集
        //$this->link=mysqli_connect($this->host,$this->login,$this->password,$this->dbname,$this->port);
        $this->link=new MySQLi($this->host,$this->login,$this->password,$this->dbname,$this->port);
        mysqli_set_charset($this->link,'utf8');
    }
    //5.完成了一个查询的方法：书写SQL语句   执行SQL语句    return
    public function querySelect($sql,$sign_date){
        $stmt=$this->link->prepare($sql) or die($this->link->error);
        #4、参数赋值（第一个参数指代参数的类型缩写，string-s,int-i,double-d,bool-b
        $stmt->bind_param("s",$sign_date);//绑定参数
        $stmt->bind_result($num);//绑定结果集
        $stmt->execute();
       /* $info=mysqli_query($this->link,$sql);
        $data=mysqli_fetch_all($info,MYSQLI_ASSOC);*/
       while($stmt->fetch()){
           return $num;
       }
    }

    public function insert($sql,$param1,$param2,$param3){
        $stmt=$this->link->prepare($sql) or die($this->link->error);;
       //3、绑定参数
       //4、参数赋值（第一个参数指代参数的类型缩写，string-s,int-i,double-d,bool-b
       $stmt->bind_param("sss",$param1,$param2,$param3);
      if($stmt->execute())
          return true;
      else
          return mysqli_error($this->link);
    }
    public function releaseConnection(){
        mysqli_close($this->link);
    }

    public function insert_Tbl_access_Log($sql,$param1,$param2,$param3,$param4,$param5,$param6,$param7){
        $stmt=$this->link->prepare($sql) or die($this->link->error);;
        //3、绑定参数
        //4、参数赋值（第一个参数指代参数的类型缩写，string-s,int-i,double-d,bool-b
        $stmt->bind_param("sssssss",$param1,$param2,$param3,$param4,$param5,$param6,$param7);
        if($stmt->execute())
            return true;
        else
            return mysqli_error($this->link);
    }
}
/*//6.实例化 调取查询的方法
$mysql=new MySql('','root','','',3309);
$data=$mysql->querySelect("select * from tbl_users");
//JSON_UNESCAPED_UNICODE 中文不编码
echo json_encode($data,JSON_UNESCAPED_UNICODE)."<br>";
//
$mysql->insert("insert into tbl_users(name) values('hi')");

$data=$mysql->querySelect("select * from tbl_users");
echo json_encode($data,JSON_UNESCAPED_UNICODE);
$mysql->releaseConnection();*/
?>
